home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
Acere (Card Game)
/
AcereÄ.sit
/
Acereƒ
/
WellDeck.cp
< prev
next >
Wrap
Text File
|
1994-08-25
|
7KB
|
269 lines
// ===========================================================================
// WellDeck.cp ⌐1993 Metrowerks Inc. All rights reserved.
// ===========================================================================
//
// Class for an object that can draw itself and respond to mouse clicks
#ifdef PowerPlant_PCH
#include PowerPlant_PCH
#endif
#include "WellDeck.h"
#include "CardDeck.h"
#include "AcereApp.h"
#include "CTextDoc.h"
#include <LDynamicArray.h>
#include <LView.h>
#include <LStream.h>
#include <PP_Messages.h>
#include <UDrawingState.h>
extern CTextDoc *theDoc;
// ---------------------------------------------------------------------------
// Ñ CreatePaneStream [static]
// ---------------------------------------------------------------------------
// Return a new Pane object initialized using data from a Stream
WellDeck*
WellDeck::CreateWellDeck(
LStream *inStream)
{
return (new WellDeck(inStream));
}
// ---------------------------------------------------------------------------
// Ñ WellDeck()
// ---------------------------------------------------------------------------
// Default Constructor
WellDeck::WellDeck()
{
mPaneID = 0;
mFrameSize.width = mFrameSize.height = 0;
mFrameLocation.h = mFrameLocation.v = 0;
mUserCon = 0;
mFrameBinding.left =
mFrameBinding.top =
mFrameBinding.right =
mFrameBinding.bottom = false;
mVisible = mActive = mEnabled = triState_Latent;
mSuperView = nil;
theDoc->theDeckWells[theDoc->currentDeckWell] = this;
theDoc->currentDeckWell++;
itsCard.card = kNoCard;
itsCard.itsOwner = this;
}
// ---------------------------------------------------------------------------
// Ñ WellDeck(const WellDeck&)
// ---------------------------------------------------------------------------
// Copy Constructor
WellDeck::WellDeck(
const WellDeck &inOriginal)
{
// Copy members of Original
mPaneID = inOriginal.mPaneID;
mFrameSize = inOriginal.mFrameSize;
mFrameLocation = inOriginal.mFrameLocation;
mFrameBinding = inOriginal.mFrameBinding;
mUserCon = inOriginal.mUserCon;
mSuperView = nil; // Copy is not inside any View
// Pane properties. If Original has
// property ON, Copy is Latent.
mVisible = inOriginal.mVisible;
if (mVisible == triState_On) {
mVisible = triState_Latent;
}
mActive = inOriginal.mActive;
if (mActive == triState_On) {
mActive = triState_Latent;
}
mEnabled = inOriginal.mEnabled;
if (mEnabled == triState_On) {
mEnabled = triState_Latent;
}
theDoc->theDeckWells[theDoc->currentDeckWell] = this;
theDoc->currentDeckWell++;
itsCard.card = kNoCard;
itsCard.itsOwner = this;
}
// ---------------------------------------------------------------------------
// Ñ WellDeck(SPaneInfo&)
// ---------------------------------------------------------------------------
// Construct Pane from data in a struct
WellDeck::WellDeck(
const SPaneInfo &inPaneInfo)
{
InitPane(inPaneInfo);
}
// ---------------------------------------------------------------------------
// Ñ WellDeck(LStream*)
// ---------------------------------------------------------------------------
// Construct Pane from data in a Stream
WellDeck::WellDeck(
LStream *inStream)
{
SPaneInfo thePaneInfo;
inStream->ReadData(&thePaneInfo, sizeof(SPaneInfo));
InitPane(thePaneInfo);
}
// ---------------------------------------------------------------------------
// Ñ InitPane
// ---------------------------------------------------------------------------
// Initialize Pane from data in a struct
void
WellDeck::InitPane(
const SPaneInfo &inPaneInfo)
{
mPaneID = inPaneInfo.paneID;
mFrameSize.width = inPaneInfo.width;
mFrameSize.height = inPaneInfo.height;
mUserCon = inPaneInfo.userCon;
mVisible = triState_Off;
if (inPaneInfo.visible) {
mVisible = triState_Latent;
}
mActive = triState_Latent;
mEnabled = triState_Off;
if (inPaneInfo.enabled) {
mEnabled = triState_Latent;
}
mFrameBinding = inPaneInfo.bindings;
mSuperView = nil;
LView *theSuperView = inPaneInfo.superView;
if (theSuperView == Default_SuperView) {
theSuperView = GetDefaultView();
}
PutInside(theSuperView);
if (theSuperView != nil) {
PlaceInSuperImageAt(inPaneInfo.left, inPaneInfo.top, false);
Boolean expandHoriz = (inPaneInfo.width < 0);
Boolean expandVert = (inPaneInfo.height < 0);
if (expandHoriz || expandVert) {
theSuperView->ExpandSubPane(this, expandHoriz, expandVert);
}
}
theDoc->theDeckWells[theDoc->currentDeckWell] = this;
theDoc->currentDeckWell++;
itsCard.card = kNoCard;
itsCard.itsOwner = this;
}
// ---------------------------------------------------------------------------
// Ñ ~WellDeck
// ---------------------------------------------------------------------------
// Destructor
WellDeck::~WellDeck()
{
PutInside(nil);
if (sLastPaneClicked == this) {
sLastPaneClicked = nil;
}
}
// ---------------------------------------------------------------------------
// Ñ Draw
// ---------------------------------------------------------------------------
// Try to draw contents of a Pane
//
// inSuperDrawRgnH specifies, in Port coordinates, the portion of the
// Pane's SuperView that needs to be drawn. Specify nil to bypass
// the intersection test.
//
// This is a wrapper function which calls DrawSelf if it is proper for
// the Pane to draw. This means that:
// > Pane's Visible property is on
// > Pane can be focused
// > Pane's Frame is in QuickDraw space
// > Pane's Frame intersects inSuperDrawRgnH
void WellDeck::Draw(RgnHandle inSuperDrawRgnH)
{
Rect frame;
if ( IsVisible() &&
FocusDraw() &&
CalcPortFrameRect(frame) &&
((inSuperDrawRgnH == nil) || RectInRgn(&frame, inSuperDrawRgnH)) )
{
if (itsCard.card == kNoCard)
{
EraseRect(&frame);
FrameRoundRect(&frame, 20, 20);
}
else
{
theDeck->DrawCard(&itsCard, frame);
FrameRoundRect(&frame, 20, 20);
}
}
}
Boolean WellDeck::CanDropOnEmptySlot(CardStruct *draggedCard)
{
// this will be overridden by most subclasses, which is why it's separate
// default behavior is that ANY card can be dropped on an empty slot
if (draggedCard->card == 1) // it's an ACE
return (true);
else
return (false);
}
Boolean WellDeck::CanDropOnSlot(CardStruct *draggedCard)
{
// this will be overridden by most subclasses.
// default behavior is that any card can be dropped on any card.
if ((draggedCard->suit == itsCard.suit) && (draggedCard->card == (itsCard.card +1)))
return (true);
else
return (false);
}
Boolean WellDeck::CanRemove(void) // can we remove cards from this pile?
{
return (false);
}
void WellDeck::AddCardToWell(CardWell *whichWell, CardStruct *whichCard)
{
CardWell::AddCardToWell(whichWell, whichCard);
if (whichCard->card == 13) // it's a King
theDoc->CheckVictory();
}